#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "fcntl.h"
#include "unistd.h"
#include "sys/types.h"
#include "sys/stat.h"

#include "pub_printf.h"

#define LEDOFF 	0
#define LEDON 	1

/**
  * @brief  提示信息打印
  * @note   
  * @param  
  * @retval 
  */
void usage_info(void)
{
	printf("\n");
	printf(F_GREEN"+++++++++++++++++++++++++++++++++++++++++\n"CLS_ALL);
	printf(F_GREEN"+       help information  @ssq          +\n"CLS_ALL);
	printf(F_GREEN"+++++++++++++++++++++++++++++++++++++++++\n"CLS_ALL);

	printf(F_YELLOW"help:\n"CLS_ALL);
	printf("use format: ./app_name /dev/device_name arg1 ... \n");
	printf("\n");

	printf(F_YELLOW"command info:\n"CLS_ALL);
	printf("  (1)load module  : insmod module_name.ko\n");
	printf("  (2)unload module: rmmod module_name.ko\n");
	printf("  (3)show module  : lsmod\n");
	printf("  (4)view device  : cat /proc/devices\n");
	printf("  (5)create device node: mknod /dev/device_name c major_num secondary_num \n");
	printf("  (6)show device node  : ls /dev/device_name \n");
	printf(F_GREEN"+++++++++++++++++++++++++++++++++++++++++\n"CLS_ALL);
}
/**
  * @brief  main主程序
  * @note   
  * @param  argc 数组元素个数
  * @param  argv 具体参数
  * @retval 0 成功;其他 失败
  */
int main(int argc, char *argv[])
{
	int fd, retvalue;
	char *filename;
	unsigned char databuf[1];
	
	if(argc != 3){
		usage_info();
		return -1;
	}

	filename = argv[1];

	/* 打开led驱动 */
	fd = open(filename, O_RDWR);
	if(fd < 0){
		PRTE("file %s open failed!\r\n", filename);
		return -1;
	}

	databuf[0] = atoi(argv[2]);	/* 要执行的操作：打开或关闭 */

	/* 向/dev/led文件写入数据 */
	retvalue = write(fd, databuf, sizeof(databuf));
	if(retvalue < 0){
		PRTE("LED Control Failed!\r\n");
		close(fd);
		return -1;
	}

	retvalue = close(fd); /* 关闭文件 */
	if(retvalue < 0){
		PRTE("file %s close failed!\r\n", filename);
		return -1;
	}
	return 0;
}



